/*
@Author   : Uyynot
@Email    : uyynot@qq.com
@Time     : 2023/8/16 15:33
@File     : snowflake.go
@Project  : web_scaff
@Desc     :
*/
package snowflake

import (
	"time"

	sf "github.com/bwmarrin/snowflake"
)

var node *sf.Node

func Init(startTime string, machineId int64) error {
	//设置起始时间
	st, err := time.Parse("2006-01-02", startTime)
	if err != nil {
		return err
	}
	sf.Epoch = st.Unix()
	node, err = sf.NewNode(machineId)
	return err
}

func GenId() int64 {
	return node.Generate().Int64()
}
